﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
using Traceability.Commont.Domains.AnimalsDomainFiles;

namespace Butcher.winform.EnterpriseForms
{
    public partial class LiveAnimalweighingUpdate : Form
    {
        int LiveAnimalweighingIds = 0;
        public LiveAnimalweighingUpdate(int LiveAnimalweighingId)
        {
            InitializeComponent();
            getType();
            this.LiveAnimalweighingIds = LiveAnimalweighingId;
            //textBox1.Text = Liveid.Cells["LiveAnimalweighingNo"].Value.ToString();
            //tb_ApproachNo.Text = Liveid.Cells["ApproachNo"].Value.ToString();
            //tb_GrossWeight.Text = Liveid.Cells["ApproachNo"].Value.ToString();
            //tb_Tare.Text = Liveid.Cells["ApproachNo"].Value.ToString();
            //tb_NetWeight.Text = Liveid.Cells["NetWeight"].Value.ToString();
            //tb_AverageWeight.Text = Liveid.Cells["AverageWeight"].Value.ToString();
            //tb_SlaughterCircleId.Text = Liveid.Cells["ApproachNo"].Value.ToString();
            //tb_SlaughterCircleNum.Text = Liveid.Cells["WeightNum"].Value.ToString();
        }

        private void LiveAnimalweighingUpdate_Load(object sender, EventArgs e)
        {
            //LiveAnimalweighing live = new(LiveAnimalweighingIds);
            //LiveAnimalweighingList liveAnimalweighingList = new(LiveAnimalweighingId);
        }
        public void getType()
        {
            SlaughterCircle res = new SlaughterCircle();
            string url = @"http://localhost:5229/api/Batch/SlaughterCraeteList";
            HttpClient client = new HttpClient();
            var content = new StringContent(JsonSerializer.Serialize<SlaughterCircle>(res));
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
            JObject info = JObject.Parse(result);
            var aaa = info["date"].Value<JArray>();
            List<SlaughterCircle> enterprises = aaa.ToObject<List<SlaughterCircle>>();
            this.comboBox1.DataSource = enterprises;
            this.comboBox1.DisplayMember = "SlaughterCircleName";
            this.comboBox1.ValueMember = "SlaughterCircledId";
        }

        private void button_Click(object sender, EventArgs e)
        {

        }
    }
}
